using MicroMsg.Common.Utils;
using MicroMsg.Manager;
using MicroMsg.Resource.@string;
using MicroMsg.Storage;
using MicroMsg.UI.Page;
using Microsoft.Phone.Controls;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Media.Imaging;
namespace MicroMsg.UI.UserContrl
{
	public class SayHelloListItemCtrl : UserControl
	{
		public delegate void ListItemClick(object sender, object object_0);
		public static ChatMsg displayMoreMsg = new ChatMsg
		{
			strTalker = "SayHelloListItemCtrlDisplayMoreMsg"
		};
		public FMessageValidInfo fMsg;
		private static ImageSource icon_man;
		private static ImageSource icon_women;
		private int mNID;
		public static DependencyProperty ListItemProperty = DependencyProperty.Register("ItemObject", typeof(ChatMsg), typeof(SayHelloListItemCtrl), new PropertyMetadata(null, new PropertyChangedCallback(SayHelloListItemCtrl.OnItemPropertyChanged)));
		private static int sNInstanceID = 0;
		private static Dictionary<int, SayHelloListItemCtrl> sDictItemIsShown = new Dictionary<int, SayHelloListItemCtrl>();
		internal Button btnLayoutRoot;
		internal Grid LayoutItem;
		internal StackPanel panelNickName;
		internal EmojiText txtNickName;
		internal Image imgSex;
		internal TextBlock txtFriendTag;
		internal Image imgHead;
		internal TextBlock txtTime;
		internal EmojiText txtSignature;
		internal Grid LayoutShowMore;
		internal TextBlock txtShowMore;
		internal PerformanceProgressBar progressBar;
		private bool _contentLoaded;
		public event SayHelloListItemCtrl.ListItemClick ItemClick;
		public ChatMsg ItemObject
		{
			get
			{
				return (ChatMsg)base.GetValue(SayHelloListItemCtrl.ListItemProperty);
			}
			set
			{
				base.SetValue(SayHelloListItemCtrl.ListItemProperty, value);
			}
		}
		public SayHelloListItemCtrl()
		{
			this.mNID = SayHelloListItemCtrl.sNInstanceID++;
			this.InitializeComponent();
			base.SetValue(TiltEffect.IsTiltEnabledProperty, true);
			this.initData();
			base.add_Loaded(new RoutedEventHandler(this.ListItem_Loaded));
			base.add_Unloaded(new RoutedEventHandler(this.ListItem_Unloaded));
		}
		private void initData()
		{
			if (SayHelloListItemCtrl.icon_man == null)
			{
				ImageSourceConverter imageSourceConverter = new ImageSourceConverter();
				string text = string.Format("/Resource/Img/CommonUse/SexIco_man.png", new object[0]);
				SayHelloListItemCtrl.icon_man = (ImageSource)imageSourceConverter.ConvertFromString(text);
				text = string.Format("/Resource/Img/CommonUse/SexIco_woman.png", new object[0]);
				SayHelloListItemCtrl.icon_women = (ImageSource)imageSourceConverter.ConvertFromString(text);
			}
		}
		private void ListItem_Unloaded(object sender, RoutedEventArgs e)
		{
			if (SayHelloListItemCtrl.sDictItemIsShown.ContainsKey(this.mNID))
			{
				SayHelloListItemCtrl.sDictItemIsShown.Remove(this.mNID);
			}
		}
		private void ListItem_Loaded(object sender, RoutedEventArgs e)
		{
			if (!SayHelloListItemCtrl.sDictItemIsShown.ContainsKey(this.mNID))
			{
				SayHelloListItemCtrl.sDictItemIsShown.Add(this.mNID, this);
			}
		}
		private static void OnItemPropertyChanged(DependencyObject dependencyObject_0, DependencyPropertyChangedEventArgs dependencyPropertyChangedEventArgs_0)
		{
			if (dependencyPropertyChangedEventArgs_0.get_Property() == SayHelloListItemCtrl.ListItemProperty)
			{
				(dependencyObject_0 as SayHelloListItemCtrl).OnListItemPropertyChanged(dependencyPropertyChangedEventArgs_0);
			}
		}
		private void OnListItemPropertyChanged(DependencyPropertyChangedEventArgs dependencyPropertyChangedEventArgs_0)
		{
			try
			{
				this.RefreshItem(dependencyPropertyChangedEventArgs_0.get_NewValue() as ChatMsg);
			}
			catch (Exception ex)
			{
				ex.ToString();
			}
		}
		private void RefreshItem(ChatMsg item)
		{
			if (item == null)
			{
				return;
			}
			if (item == SayHelloListItemCtrl.displayMoreMsg)
			{
				this.LayoutShowMore.set_Background(R.theme.SHAKE_SHOW_MORE_BK_BRUSH);
				this.txtShowMore.set_Visibility(0);
				this.progressBar.set_Visibility(1);
				this.progressBar.IsIndeterminate = false;
				this.LayoutItem.set_Visibility(1);
				this.LayoutShowMore.set_Visibility(0);
				return;
			}
			this.LayoutShowMore.set_Visibility(1);
			this.LayoutItem.set_Visibility(0);
			this.fMsg = FMessageHelper.GetFmessageValidInfo(item);
			if (this.fMsg == null)
			{
				return;
			}
			this.imgHead.set_Source(HeadImgMgr.getHeadImage(this.fMsg.UserName, true));
			this.txtTime.set_Text(Util.formatTimeInList(item.nCreateTime, true));
			Contact contact = StorageMgr.contact.method_0(this.fMsg.UserName);
			if (contact != null && ContactMgr.isContact(contact))
			{
				this.txtFriendTag.set_Visibility(0);
				this.txtNickName.set_MaxWidth(this.panelNickName.get_Width() - this.txtFriendTag.get_ActualWidth() - this.txtTime.get_ActualWidth() - 40.0);
			}
			else
			{
				this.txtNickName.set_MaxWidth(this.panelNickName.get_Width() - this.txtTime.get_ActualWidth() - 40.0);
				this.txtFriendTag.set_Visibility(1);
			}
			this.txtNickName.Text = this.fMsg.NickName;
			bool flag = this.fMsg.content == null || this.fMsg.content.get_Length() == 0;
			this.txtSignature.Text = (flag ? strings.Con_Detail_StrSayHiDeft : this.fMsg.content);
			this.txtNickName.Foreground = R.theme.LISTA_NAME_WORD_BRUSH;
			this.txtTime.set_Foreground(R.theme.LISTA_TAG_WORD_BRUSH);
			this.txtSignature.Foreground = R.theme.LISTA_SIGNATURE_WORD_BRUSH;
			if (1 == this.fMsg.int_0)
			{
				this.imgSex.set_Source(SayHelloListItemCtrl.icon_man);
				this.imgSex.set_Visibility(0);
				return;
			}
			if (2 == this.fMsg.int_0)
			{
				this.imgSex.set_Source(SayHelloListItemCtrl.icon_women);
				this.imgSex.set_Visibility(0);
				return;
			}
			this.imgSex.set_Visibility(1);
		}
		public static void RefreshHeadImgInView(List<string> listUserGetHeadImg)
		{
			if (listUserGetHeadImg == null)
			{
				return;
			}
			IEnumerable<SayHelloListItemCtrl> values = SayHelloListItemCtrl.sDictItemIsShown.get_Values();
			Enumerable.Reverse<SayHelloListItemCtrl>(values);
			using (List<string>.Enumerator enumerator = listUserGetHeadImg.GetEnumerator())
			{
				while (enumerator.MoveNext())
				{
					string current = enumerator.get_Current();
					if (current != null)
					{
						using (IEnumerator<SayHelloListItemCtrl> enumerator2 = values.GetEnumerator())
						{
							while (enumerator2.MoveNext())
							{
								SayHelloListItemCtrl current2 = enumerator2.get_Current();
								string text = (current2.fMsg != null) ? current2.fMsg.UserName : null;
								if (text == current)
								{
									current2.imgHead.set_Source(HeadImgMgr.getHeadImage(current, true));
								}
							}
						}
					}
				}
			}
		}
		public static void ShowInViewItemsCachedImg()
		{
			List<SayHelloListItemCtrl> list = Enumerable.ToList<SayHelloListItemCtrl>(SayHelloListItemCtrl.sDictItemIsShown.get_Values());
			using (List<SayHelloListItemCtrl>.Enumerator enumerator = list.GetEnumerator())
			{
				while (enumerator.MoveNext())
				{
					SayHelloListItemCtrl current = enumerator.get_Current();
					if (current.ItemObject != null)
					{
						string userInfo = (current.fMsg != null) ? current.fMsg.UserName : null;
						BitmapImage cacheHeadImage = HeadImgMgr.getCacheHeadImage(userInfo);
						if (cacheHeadImage != current.imgHead.get_Source())
						{
							current.imgHead.set_Source(cacheHeadImage);
						}
					}
				}
			}
		}
		private void btnLayoutRoot_Click(object sender, RoutedEventArgs e)
		{
			if (this.ItemClick != null)
			{
				this.ItemClick(this, this.ItemObject);
			}
		}
		[DebuggerNonUserCode]
		public void InitializeComponent()
		{
			if (this._contentLoaded)
			{
				return;
			}
			this._contentLoaded = true;
			Application.LoadComponent(this, new Uri("/MicroMsg;component/Source/Plugin/Lbs/UI/SayHelloListItemCtrl.xaml", 2));
			this.btnLayoutRoot = (Button)base.FindName("btnLayoutRoot");
			this.LayoutItem = (Grid)base.FindName("LayoutItem");
			this.panelNickName = (StackPanel)base.FindName("panelNickName");
			this.txtNickName = (EmojiText)base.FindName("txtNickName");
			this.imgSex = (Image)base.FindName("imgSex");
			this.txtFriendTag = (TextBlock)base.FindName("txtFriendTag");
			this.imgHead = (Image)base.FindName("imgHead");
			this.txtTime = (TextBlock)base.FindName("txtTime");
			this.txtSignature = (EmojiText)base.FindName("txtSignature");
			this.LayoutShowMore = (Grid)base.FindName("LayoutShowMore");
			this.txtShowMore = (TextBlock)base.FindName("txtShowMore");
			this.progressBar = (PerformanceProgressBar)base.FindName("progressBar");
		}
	}
}
